<template>
  <div class="body" v-loading="loading">
    <div>
      <el-button type="info" size="small" icon="el-icon-back" @click="gotoList">&nbsp;返&nbsp;回&nbsp;</el-button>
    </div>
    <el-form ref="form" :model="header" size="small" label-width="80px" :inline="true" class="header">
      <div class="audit_icon iconfont" v-if="header.status === 'audit'"></div>
      <el-row>
        <el-col :span="6">
          <el-form-item label="订货单号">{{ header.billNo }}</el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="订货日期">{{ header.orderDate }}</el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item label="订货箱数">{{ header.boxCount }}</el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="订货重量">{{ header.count ? Number(header.count.toFixed(6)): header.count }}</el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="所属门店">{{ header.department }}</el-form-item>
        </el-col>
      </el-row>
      <br />
    </el-form>
    <el-table :data="dataList" class="detail" height="67vh">
      <el-table-column label="No." width="60" align="right" type="index"></el-table-column>
      <el-table-column label="产品大类" min-width="120" prop="prdBigType"></el-table-column>
      <el-table-column label="产品编码" min-width="120" prop="materialNo"></el-table-column>
      <el-table-column label="产品名称" min-width="120" prop="materialName"></el-table-column>
      <el-table-column label="产品规格" min-width="120" prop="materialSpec"></el-table-column>
      <el-table-column label="数量" min-width="100" align="right">
        <template #default="scope">
          {{ scope.row.count }}{{ scope.row.unit }}
        </template>
      </el-table-column>
      <el-table-column label="建议零售单价" min-width="120" prop="price"></el-table-column>
      <el-table-column label="折扣" min-width="120" prop="discount"></el-table-column>
      <el-table-column label="折扣后金额" min-width="120" prop="discountCount"></el-table-column>
      <el-table-column label="平均单价" min-width="120" prop="avePrice"></el-table-column>
      <el-table-column label="是否为赠品" min-width="120" prop="isGift"></el-table-column>
      <el-table-column label="备注" min-width="120" prop="remark"></el-table-column>
      <el-table-column label="成交价折扣" min-width="120" prop="dealDiscount"></el-table-column>
      <el-table-column label="折扣后单价（促销活动价）" min-width="120" prop="discountPrice"></el-table-column>
      <el-table-column label="提成品" min-width="120" prop="commissionPrd"></el-table-column>
    </el-table>
  </div>
</template>

<script>
import dayjs from 'dayjs'
import { getBoxNo } from '../../utils'

export default {
  data() {
    return {
      loading: false,
      materialLoading: false,
      materialList: [],
      supplierLoading: false,
      supplierList: [],
      header: {},
      dataList: [],
      detailBoxList: [],
      selection: [],
      stockList: [],
      unitList: [],
    }
  },
  async mounted() {
    await this.getStock()
    let billNo = this.$route.query.billNo
    if (billNo) {
      return this.getBill(billNo)
    }
  },
  methods: {
    async getStock() {
      this.loading = true;
      try {
        let res = await this.$api.getChildDictionaryListByKeys({
          keys: ['stock']
        });
        if (!res.res) return;
        this.stockList = res.stock;
      } finally {
        this.loading = false;
      }
    },
    /**
     * 获取状态名
     */
    getStockName(val) {
      if (this.stockList && this.stockList.length > 0) {
        for(let i = 0; i < this.stockList.length; i++) {
          if (this.stockList[i].key === val) {
            return this.stockList[i].name;
          }
        }
      }
      return '';
    },
    gotoList() {
      return this.$router.push('/sale/saleStoreSaleList')
    },
    async getBill(billNo) {
      this.loading = true
      try {
        let res = await this.callApi('get_sale_store_sale_bill_detail', {
          billNo: billNo,
        })
        if (res.res) {
          this.header = res.header || {}
          this.dataList = res.data || []
        }
      } finally {
        this.loading = false
      }
    },
  }
}
</script>

<style lang="scss" scoped>
.body {
  padding: 20px 0;
  .header {
    margin-top: 20px;
    position: relative;
    .header_row {
      display: flex;
      >div {
        flex-shrink: 0;
      }
      :deep(.produceDate) {
        .el-input {
          width: 100%!important;
        }
      }
    }
    .audit_icon {
      position: absolute;
      top: -10px;
      left: 60px;
      font-size: 48px;
      color: red;
    }
    .material {
      width: 100%;
    }
    .p3 {
      :deep(.el-form-item__content) {
        display: flex;
        .comment {
          margin-left: 10px;
          word-break: keep-all;
        }
      }
    }
  }
  .detail_header {
    display: flex;
    justify-content: space-between;
    margin-top: 10px;
    .stat {
      display: flex;
      font-size: 15px;
      >div {
        display: flex;
        align-items: baseline;
        line-height: 32px;
        .label {
          text-align: right;
          margin-right: 5px;
          color: #aaa;
        }
        .value {
          min-width: 50px;
          margin-right: 10px;
          color: #666;
        }
      }
    }
  }
}
</style>
